package com.huawei.updatesdk.a.a.c;

import com.huawei.updatesdk.a.a.b.a.a.a;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public abstract class d {
    private static final String a = d.class.getSimpleName();

    public static Class a(Field field) {
        return Map.class.isAssignableFrom(field.getType()) ? a(field, 1) : List.class.isAssignableFrom(field.getType()) ? a(field, 0) : null;
    }

    private static Class a(Field field, int i) {
        Type genericType = field.getGenericType();
        if (genericType instanceof ParameterizedType) {
            Type[] actualTypeArguments = ((ParameterizedType) genericType).getActualTypeArguments();
            if (actualTypeArguments != null && actualTypeArguments.length > i) {
                try {
                    if (actualTypeArguments[i] instanceof Class) {
                        return (Class) actualTypeArguments[i];
                    }
                    String obj = actualTypeArguments[i].toString();
                    int indexOf = obj.indexOf("class ");
                    int i2 = indexOf < 0 ? 0 : indexOf;
                    indexOf = obj.indexOf("<");
                    if (indexOf < 0) {
                        indexOf = obj.length();
                    }
                    return Class.forName(obj.substring(i2, indexOf));
                } catch (ClassNotFoundException e) {
                    a.d(a, "getType exception!" + e.getMessage());
                }
            }
        }
        return null;
    }

    public static Field[] a(Class cls) {
        Object obj = null;
        if (cls.getSuperclass() != null) {
            obj = a(cls.getSuperclass());
        }
        Object declaredFields = cls.getDeclaredFields();
        if (obj == null || obj.length <= 0) {
            obj = declaredFields;
        } else {
            Object obj2 = new Field[(declaredFields.length + obj.length)];
            System.arraycopy(obj, 0, obj2, 0, obj.length);
            System.arraycopy(declaredFields, 0, obj2, obj.length, declaredFields.length);
            Field[] fieldArr = obj2;
        }
        List arrayList = new ArrayList();
        for (Field field : fieldArr) {
            if (field.getName().indexOf("$") < 0) {
                arrayList.add(field);
            }
        }
        if (arrayList.size() == fieldArr.length) {
            return fieldArr;
        }
        fieldArr = new Field[arrayList.size()];
        arrayList.toArray(fieldArr);
        return fieldArr;
    }
}
